package Classic150;

import Tree.TreeNode;

public class 将有序数组转换为二叉搜索树 {
    /*
        典型分治
     */
    public TreeNode sortedArrayToBST(int[] nums) {
        return buildTree(nums, 0, nums.length - 1);
    }

    private TreeNode buildTree(int[] nums, int left, int right) {
        if (left > right) return null;
        int index = (left + right) / 2;
        TreeNode root = new TreeNode(nums[index]);
        root.left = buildTree(nums, left, index - 1);
        root.right = buildTree(nums, index + 1, right);
        return root;
    }
}
